package com.imay.live.activity.family.controller;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.imay.live.R;
import com.imay.live.model.FamilyModel;
import com.imay.live.model.FamilyUserModel;
import com.imay.live.utils.GlideUtil;
import com.imay.live.utils.ViewUtil;
import com.imay.live.view.FamilyItemView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/18 0018.
 */

public class FamilySettingController extends BaseFamilyController {

    FamilyItemView fiv_family_users;
    ImageView iv_hear_img_ranking;
    TextView tv_family_lv, tv_family_des, tv_family_name;
    View ll_family, ll_family_permission;

    @Override
    protected void initView() {
        fiv_family_users = ViewUtil.findView(activity, R.id.fiv_family_users);
        iv_hear_img_ranking = ViewUtil.findView(activity, R.id.iv_hear_img_ranking);
        tv_family_lv = ViewUtil.findView(activity, R.id.tv_family_lv);
        tv_family_name = ViewUtil.findView(activity, R.id.tv_family_name);
        tv_family_des = ViewUtil.findView(activity, R.id.tv_family_des);

        ll_family = ViewUtil.findView(activity, R.id.ll_family);
        fiv_family_users = ViewUtil.findView(activity, R.id.fiv_family_users);
        ll_family_permission = ViewUtil.findView(activity, R.id.ll_family_permission);

        if (activity instanceof View.OnClickListener) {
            ll_family.setOnClickListener((View.OnClickListener) activity);
            fiv_family_users.setOnClickListener((View.OnClickListener) activity);
            ll_family_permission.setOnClickListener((View.OnClickListener) activity);
        }
    }

    public void setFamilyInfoData(FamilyModel familyInfoData) {
        GlideUtil.loadRectangleImage(iv_hear_img_ranking, familyInfoData.getUrl(), R.dimen.radius_4x);
        tv_family_lv.setText(String.valueOf(familyInfoData.getLv()));
        tv_family_name.setText(familyInfoData.getName());
        tv_family_des.setText(familyInfoData.getAnnouncement());
        fiv_family_users.setTitle(R.string.str_family_person_text);
        fiv_family_users.setUserCount(familyInfoData.getCount());
    }

    public void setUserData(FamilyUserModel userData) {
        if (userData == null) {
            return;
        }
        List<String> images = new ArrayList<>();
        List<Integer> familyAdmin = new ArrayList<>();
        for (FamilyUserModel.FamilyUsersBean user : userData.getFamilyUsers()) {
            images.add(user.getImgHead());
            familyAdmin.add(user.getAdmin());
        }
        fiv_family_users.setNewData(images, false);
        fiv_family_users.setAdmin(familyAdmin);
    }
}
